package svc

import (
	"github.com/eeppee_admin/clouddisk/service/internal/config"
	"github.com/eeppee_admin/clouddisk/service/model"
	"xorm.io/xorm"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-redis/redis/v8"

	"github.com/zeromicro/go-zero/rest"
	"github.com/eeppee_admin/clouddisk/service/internal/middleware"

)

// 服务上下文
type ServiceContext struct {
	Config config.Config

	// 需要Xorm, Mysql 客户端
	Engine *xorm.Engine
	// 需要Redis 客户端
	RDB *redis.Client

	Auth rest.Middleware

}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config: c,
		Engine: model.Init(c.Mysql.DataSource),
		RDB: model.InitRedis(c),
		Auth: middleware.NewAuthMiddleware().Handle,
	}
}
